package org.seven.cpcrkapp.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import org.seven.cpcrkapp.App;

import java.util.List;

public abstract class CacheUtils {
    private static String FILE_NAME = "CACHE";
    public static String DICT_PH = "dict_ph";
    public static String DICT_LH = "dict_lh";
    public static String DICT_LC = "dict_lc";
    public static String DICT_KS = "dict_ks";

    public static void clear(){
        SharedPreferences.Editor editor = App.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.clear();
        editor.commit();
    }

    public static void put(String key, String value) {
        SharedPreferences.Editor editor = App.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).edit();
        editor.putString(key, value);
        editor.apply();
    }

    public static String get(String key) {
        SharedPreferences sharedPreferences = App.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(key, "");
    }

    public static String[] getList(String key) {
        String json = get(key);
        if ("".equals(json)) {
            return null;
        }
        return JsonUtils.getValue(json, String[].class);
    }
}
